package com.neuedu.dao.Imp;


import cn.hutool.db.Db;
import cn.hutool.db.Entity;
import com.alibaba.druid.pool.DruidDataSource;
import com.neuedu.dao.ShopTypeDao;
import com.neuedu.pojo.ShopType;
import com.neuedu.utils.JDBCUtil;

import javax.sql.DataSource;
import java.util.List;

public class ShopTypeDaoImp implements ShopTypeDao {
    private DataSource dataSource = JDBCUtil.getDruidDataSource();

    // 查询店铺类别数据
    @Override
    public List<ShopType> getShopType() throws Exception{
        return Db.use(dataSource).query("select * from shop_category",ShopType.class);
    }

    @Override
    public Integer addShopType(String categoryName) throws Exception{
        return Db.use(dataSource).insert(Entity.create("shop_category").set("category_name",categoryName));
    }

    @Override
    public Integer updateShopType(String shopCategoryId, String categoryName) throws Exception{
        return Db.use(dataSource).update(
                Entity.create().set("shop_category_id",shopCategoryId),
                Entity.create("shop_category").set("category_name",categoryName)
        );
    }

    @Override
    public Integer delShopType(String shopCategoryId) throws Exception {
        return Db.use(dataSource).del(Entity.create("shop_category").set("shop_category_id",shopCategoryId));
    }
}
